package com.paradogs.demo.logic.controller;

import com.paradogs.demo.logic.event.PlayerLoginEvent;
import com.paradogs.demo.logic.misc.PlayerOnlineHolder;
import com.paradogs.demo.logic.misc.PlayerTemplate;
import com.paradogs.demo.logic.service.RoleService;
import com.paradogs.framework.common.entity.Role;
import com.paradogs.framework.common.pojo.misc.LongWrapper;
import com.paradogs.framework.core.annoations.request.PRController;
import com.paradogs.framework.core.annoations.request.PRMsgMapping;
import com.paradogs.framework.core.msg.GCAck;
import com.paradogs.framework.core.msg.PRMsgContextHolder;
import com.paradogs.framework.core.utils.EventUtils;
import com.paradogs.framework.core.utils.MsgUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author: yumi
 * @date: 2023/11/29  9:56
 * @Description: TODO
 */
@Slf4j
@PRController
@PRMsgMapping("role")
public class RoleController {

    @Autowired
    private PlayerOnlineHolder playerOnlineHolder;

    @Autowired
    private RoleService roleService;

    @PRMsgMapping(value = "loadPlayer", async = true)
    public GCAck loadPlayer(LongWrapper wrapper) {
        // 初始化玩家数据
        Long uid = wrapper.getVal();
        PlayerTemplate playerTemplate = new PlayerTemplate(uid);
        EventUtils.publishEvent(new PlayerLoginEvent(uid, playerTemplate));
        log.info("Load Player: {}", uid);
        return GCAck.success();
    }

    /**
     * 打怪测试
     */
    @PRMsgMapping("addExp")
    public void kill() {
        PlayerTemplate player = playerOnlineHolder.getPlayer(PRMsgContextHolder.getPlayerId());
        player.getRoleManager().addExp();
    }

    /**
     * 获取指定等级升级所需的经验
     * @param wrapper
     */
    @PRMsgMapping("getLevelExp")
    public void getLevelExp(LongWrapper wrapper) {
        roleService.getLevelExp(wrapper.getVal());
    }


}
